import Cookies from 'js-cookie'
let db = {
  save (key, value) {
    localStorage.setItem(key, JSON.stringify(value))
    Cookies.set(key,value)
  },
  get (key, defaultValue = {}) {
    return JSON.parse(localStorage.getItem(key)) || defaultValue
  },
  remove (key) {
    localStorage.removeItem(key)
  },
  clear () {
    localStorage.clear()
    //清除所有cookie函数
    let date = new Date()
    date.setTime(date.getTime()-10000)
    let keys=document.cookie.match(/[^ =;]+(?=\=)/g)
    if (keys) {
      for (var i =  keys.length; i--;)
        document.cookie=keys[i]+"=; expire="+date.toGMTString()+"; path=/"
    }
  }
}
export default db
